package com.nl.util;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.apache.commons.dbutils.DbUtils;
import org.apache.log4j.Logger;





public class Common {
	
	private static final Logger logger = Logger.getLogger(Common.class);
	private static final String sKey;

	static{
		sKey = ConfigUtils.getInstance().getValue("sKey");
	}
	/**
	 * 发送告警短信
	 * @param content 短信内容
	 */
	public static void sendWarnSms(String content) {
		Connection conn = null;
		PreparedStatement pres = null;
		String sql = "insert into boss_sm_send(id,receiver,sender,content,result,create_date,modify_date,city_id,city_ext_id)" +
				"values(seq_bomc_cmpp.nextval,?,?,?,?,sysdate,sysdate,?,?)";
		try {
			conn = ConnectionManager.getInstance().getConnection();
			pres = conn.prepareStatement(sql);
			String msisdn = ConfigUtils.getInstance().getValue("msisdn");
			String[] msisdns = msisdn.split("\\,");
			for (String str : msisdns) {
//				str = AES.encrypt(str, sKey);
				pres.setString(1, str);
				pres.setString(2, ConfigUtils.getInstance().getValue("sender"));
				pres.setString(3, content);
				pres.setInt(4, -1);//默认未处理
				pres.setInt(5, 25);
				pres.setString(6, "25002");
				pres.addBatch();
			}	
			pres.executeBatch();
		} catch (Exception e) {
			logger.error("插入短信内容时出现异常···");
			e.printStackTrace();
		} finally {
			DbUtils.closeQuietly(conn, pres, null);
		}
	}
}
